package home.ex.todolist.server;

import home.ex.todolist.client.action.GetAllTodo;
import home.ex.todolist.client.action.GetAllTodoResult;

import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class GetAllTodoActionHandler implements ActionHandler<GetAllTodo, GetAllTodoResult> {
    
    private TodoService todoService;
    
    @Inject
    public void setTodoService(final TodoService todoService) {
	this.todoService = todoService;
    }
    
    @Inject
    public GetAllTodoActionHandler() {
    }
    
    @Override
    public GetAllTodoResult execute(final GetAllTodo action, final ExecutionContext context) throws ActionException {
	final GetAllTodoResult result = new GetAllTodoResult();
	result.setTodos(this.todoService.getAllTodo());
	return result;
    }
    
    @Override
    public void undo(final GetAllTodo action, final GetAllTodoResult result, final ExecutionContext context)
	    throws ActionException {
    }
    
    @Override
    public Class<GetAllTodo> getActionType() {
	return GetAllTodo.class;
    }
}
